package com.programming.movie.manager.impl;

import java.util.List;

import com.programming.common.exception.DAOException;
import com.programming.common.exception.ManagerException;
import com.programming.common.page.Page;
import com.programming.movie.dao.MovieInfoDAO;
import com.programming.movie.dataobject.MovieInfo;
import com.programming.movie.manager.MovieInfoManager;

public class MovieInfoManagerImpl implements MovieInfoManager {
	private MovieInfoDAO movieInfoDAO;

	public void setMovieInfoDAO(MovieInfoDAO movieInfoDAO) {
		this.movieInfoDAO = movieInfoDAO;
	}

	@Override
	public boolean delete(Long id) throws ManagerException {
		// TODO Auto-generated method stub
		try {
			this.movieInfoDAO.delete(id);
		} catch (DAOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public MovieInfo getById(Long id) throws ManagerException {
		try {
			return this.movieInfoDAO.getById(id);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Page query(MovieInfo movieInfo, int start, int limit) throws ManagerException {
		try {
			return this.movieInfoDAO.query(movieInfo, start, limit);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<MovieInfo> queryList(MovieInfo movieInfo) throws ManagerException {
		try {
			return this.movieInfoDAO.queryList(movieInfo);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}

	@Override
	public boolean save(MovieInfo movieInfo) throws ManagerException {
		if (movieInfo.getId() != null) {
			try {
				this.movieInfoDAO.update(movieInfo);
			} catch (DAOException e) {
				e.printStackTrace();
				return false;
			}
		} else {
			try {
				this.movieInfoDAO.insert(movieInfo);
			} catch (DAOException e) {
				e.printStackTrace();
				return false;
			}
		}
		return true;
	}

}
